package com.aliyeye.config;

import com.aliyeye.interceptor.MySpringBootInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @version V999
 * @package com.aliyeye.config
 * @description: 来自三年开发经验，月薪100k，大佬代码
 * @author: 痞子洋
 * @date: 2019/6/9 21:29
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
/*  @Autowired
    private  MySpringBootInterceptor mySpringBootInterceptor;*/
    /**
     * 将自定义拦截器注入到springIOC容器中。
     *
     * @return
     */
    @Bean
    public MySpringBootInterceptor mySpringBootInterceptor() {
        return new MySpringBootInterceptor();
    }

    /**
     * 重写接口中的addInterceptors方法，调用addInterceptor方法（参数为自定义拦截器对象）
     * 添加自定义拦截器 并添加拦截路径
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(mySpringBootInterceptor()).addPathPatterns("/*");
    }
}
